<!-- 团队管理 -->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入团队名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属单位" prop="companyId">
        <SelectCompany
          :defaultValue.sync="queryParams.companyId"
          placeholder="请选择所属单位"
          :companyType="0"
          @change="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb-8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['company:groups:add']"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="groupsList">
      <el-table-column
        label="团队码"
        prop="teamCode"
        align="center"
        width="120"
      ></el-table-column>
      <el-table-column
        label="团队头像"
        prop="teamImg"
        align="center"
        width="120"
      >
        <template slot-scope="{ row }">
          <image-preview
            v-if="row.teamImg"
            :src="row.teamImg"
            :width="30"
            :height="30"
          />
        </template>
      </el-table-column>
      <el-table-column label="团队名称" prop="teamName" align="center">
        <template slot-scope="{ row }">
          <div class="colorZS cup" @click="goDetails(row)">{{ row.teamName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="团队成员"
        prop="expertNum"
        align="center"
        width="100"
      />
      <el-table-column
        label="签约用户"
        prop="userNum"
        align="center"
        width="100"
      />
      <el-table-column label="团队负责人" prop="leaderName" align="center" />
      <el-table-column label="所属单位" prop="companyName" align="center" />
      <el-table-column
        label="创建时间"
        prop="createTime"
        align="center"
        width="200"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <EditGroups ref="EditGroups" @refresh="getList" />
  </div>
</template>

<script>
import SelectCompany from "@/components/SelectCompany";
import { getTeamList } from "@/api/company/groups";
import EditGroups from './editGroups';

export default {
  name: "Groups",
  components: {
    SelectCompany,
    EditGroups
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: "",
        companyId: ""
      },
      groupsList: [],
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      getTeamList(this.queryParams).then((response) => {
        this.groupsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd() {
      this.$refs.EditGroups.openDialog()
    },
    goDetails(row){
      this.$router.push({path: `/company/groupsDetails/index/${row.teamId}`});
    }
  },
};
</script>

<style lang="scss" scoped></style>
